home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 1995 November / Macworld Nov ’95.toast / Developers / BoxMaker++ / ll-R ƒ / ll_r_shell.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-06-14  |  2.9 KB  |  141 lines  |  [TEXT/KAHL]

  1.  
  2. class ll_r_settings
  3. {
  4.     public:
  5.         enum
  6.         {
  7.             kType = 1,
  8.             kCreator,
  9.             kSize,
  10.             kBytes,
  11.             kKiloBytes,
  12.             kCreatDate,
  13.             kModDate,
  14.             kBakDate,
  15.             kTimes,
  16.  
  17.             kTabs,
  18.             kSpaces,
  19.             kAskFileName,
  20.             kIndentFolders,
  21.             kNumButtons
  22.         };
  23.         Boolean myPrefs[ kNumButtons];
  24. };
  25.  
  26. typedef preferences<ll_r_settings> ll_r_prefs;
  27.  
  28. #pragma template preferences<ll_r_settings>;
  29.  
  30. class ll_r_shell : public boxmaker, public ll_r_prefs
  31. {
  32.     public:
  33.         ll_r_shell( Str255 prefsFileName, ll_r_settings defaultsettings);
  34.         ~ll_r_shell();
  35.  
  36.         virtual void EnterFolder( Boolean opening);
  37.         virtual void OpenDoc( Boolean opening);
  38.         virtual void CantEnterFolder( Boolean opening);
  39.         virtual void ExitFolder( Boolean opening);
  40.  
  41.         virtual void StartABunch( long numTopLevelItems, Boolean opening);
  42.  
  43.         virtual void HandleDialogEvent( short itemHit, DialogPtr theDialog);
  44.  
  45.     private:
  46.         short outFileNo;
  47.         long  outVRefNum;
  48.                 
  49.         void SetupDialog( DialogPtr theDialog);
  50.         void FlipButton( DialogPtr theDialog, short theItem);
  51.  
  52.         long indentationLevel;
  53.         unsigned char plentySpace[ 1000];
  54.         unsigned char delimiter;
  55.         //
  56.         // 'append' appends the specified string to 'plentySpace'
  57.         // without checking for running out of space. It uses and
  58.         // updates 'currentEnd', and also appends a delimiter as
  59.         // specified by the preferences.
  60.         //
  61.         unsigned char *currentEnd;
  62.         void append( char letter);
  63.         void append( char *item, int len);
  64.         void append( unsigned char *item);        // appends a Pascal string
  65.         void append( char *item);                // appends a C string
  66.         void appendDate( unsigned long seconds);
  67.         void append2Digits( short number);
  68.         void RemoveLastChar();
  69.         void ChangeLastToNewLine();
  70.         void StartNewLine();
  71.         long KiloBytes( long bytes);
  72. };
  73.  
  74. inline void ll_r_shell::EnterFolder( Boolean opening)
  75. {
  76.     if( myPrefs[ kIndentFolders])
  77.     {
  78.         //
  79.         // Note: we do not use 'delimiter' for the first characters.
  80.         // Instead we always use a tab there. I think this looks nicer.
  81.         //
  82.         plentySpace[ indentationLevel] = '\t';
  83.         indentationLevel += 1;
  84.     }
  85. }
  86.  
  87. inline void ll_r_shell::ExitFolder( Boolean opening)
  88. {
  89.     if( myPrefs[ kIndentFolders])
  90.     {
  91.         indentationLevel -= 1;
  92.     }
  93. }
  94.  
  95. inline void ll_r_shell::append( char letter)
  96. {
  97.     *currentEnd++ = letter;
  98. }
  99.  
  100. inline void ll_r_shell::append( unsigned char *item)
  101. {
  102.     const int len = *item;
  103.     append( (char *)item + 1, len);
  104. }
  105.  
  106. inline void ll_r_shell::append( char *item)
  107. {
  108.     while( *item != 0)
  109.     {
  110.         *currentEnd++ = *item++;
  111.     }
  112. }
  113.  
  114. inline void ll_r_shell::append2Digits( short number)
  115. {
  116.     const short lastdigit  = number % 10;
  117.     const short firstdigit = (number / 10) % 10;
  118.     append( firstdigit + '0');
  119.     append( lastdigit  + '0');
  120. }
  121.  
  122. inline void ll_r_shell::RemoveLastChar()
  123. {
  124.     currentEnd -= 1;
  125. }
  126.  
  127. inline void ll_r_shell::ChangeLastToNewLine()
  128. {
  129.     currentEnd[ -1] = '\r';
  130. }
  131.  
  132. inline void ll_r_shell::StartNewLine()
  133. {
  134.     currentEnd = &plentySpace[ indentationLevel];
  135. }
  136.  
  137. inline long ll_r_shell::KiloBytes( long bytes)
  138. {
  139.     return ((bytes + 1023) >> 10);
  140. }
  141.